﻿using System;
using System.Drawing;
using System.Collections;
using System.Data;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using LED.Helper; 
using SXC.LED.Control;
namespace TInsigmaLEDDriver
{
    public class WrapLEDDriver
    { 
        #region====Defination======
       static Int32 dev = 0; 

        /*   

         */
        #endregion
        /// <summary>
        /// 3.1	动态链接库初始化:
        /// 定义：int InsigmaLEDDriver_Init( void ); 
        /// 功能：初始化动态链接库，将需要进行DLL初始化的代码放在这个函数中.
        /// 输入：无.
        /// 返回：成功返回0，失败返回-1
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("InsigmaLEDDriver_Init", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 InsigmaLEDDriver_Init()
        {

            Int32 result = 0;
            try
            {
                SXCLEDControl.InsigmaLEDDriver_Init(); 
            }
            catch (Exception ex)
            {
                
            }
            return result;
        }
        /// <summary>
        /// 3.2	清理动态链接库
        /// 定义：void InsigmaLEDDriver_Cleanup( void );
        /// 功能：卸载动态链接库，将需要进行DLL卸载的代码放在这个函数里，比如设备内存释放等
        /// 输入：无.
        /// 返回：无.
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("InsigmaLEDDriver_Cleanup", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 InsigmaLEDDriver_Cleanup()
        {

            Int32 result = 0;
            SXCLEDControl.InsigmaLEDDriver_Cleanup();
            return result;
        }
        /// <summary>
        /// 3.3	检查LED设备是否正常
        /// 定义：int LED_IsDeviceOK( int nLEDID );
        /// 功能：检测指定的屏幕显示设备是否正常运行
        /// 输入：nLEDID - 设备ID；
        /// 返回：0表示正常， -1表示出现异常。
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_IsDeviceOK", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_IsDeviceOK(int nLEDID)
        {

            Int32 result = 0;
            try
            {
                result = SXCLEDControl.LED_IsDeviceOK(nLEDID);
            }
            catch (Exception ex)
            {
                
            }
            return result;
        }
        /// <summary>
        /// 3.4	屏幕开关控制
        /// 定义: int LED_SwitchPower( int nLEDID, int nTurnOn );
        /// 功能：对远程显示屏设备进行开关控制
        /// 输入: nLEDID - 设备ID号
        /// nTurnOn – 1表示打开设备 0表示关闭设备
        /// 返回：成功返回0，失败返回-1
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_SwitchPower", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_SwitchPower(int nLEDID, int nTurnOn)
        {

            Int32 result = 0;
            try
            {
                result = SXCLEDControl.LED_SwitchPower(nLEDID, nTurnOn);
            }
            catch (Exception ex)
            {
                
            }
            return result;
        }
        /// <summary>
        /// 3.5	检查设备是否开启
        /// 定义: int LED_IsDeviceTurnOn( int nLEDID );
        /// 功能：查询远程显示设备是否打开
        /// 输入: nLEDID – 设备ID号
        /// 返回: 0 表示关闭， 1表示打开
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_IsDeviceTurnOn", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_IsDeviceTurnOn( int nLEDID )
        {

            Int32 result = 0;
            try
            {
            result=SXCLEDControl.LED_IsDeviceTurnOn(nLEDID);
           }
            catch (Exception ex)
            {
                
            }
            return result;
        }
        /// <summary>
        /// 3.6 检测设备是否离线
        /// 定义: int LED_IsDeviceOffline( int nLEDID );
        /// 功能: 检测指定的LED显示屏设备是否处于离线状态
        /// 输入: nLEDID – 设备ID号
        /// 返回: 0 表示离线 1 表示在线
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_IsDeviceOffline", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_IsDeviceOffline(int nLEDID)
        {
            Int32 result = 0;
            SXCLEDControl.InsigmaLEDDriver_Cleanup();
            return result;
        }
        /// <summary>
        /// 3.7 设置屏幕的亮度值
        /// 定义: int LED_SetBright( int nLEDID, int lValue );
        /// 功能: 设置指定显示屏的屏幕亮度
        /// 输入: nLEDID – 设备ID号
        /// lValue – 亮度值
        /// 返回：成功返回0，失败返回-1.
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_SetBright", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_SetBright(int nLEDID, int lValue)
        {

            Int32 result = 0;
            SXCLEDControl.InsigmaLEDDriver_Cleanup();
            return result;
        }
        /// <summary>
        /// 3.7 设置屏幕的亮度值
        /// 定义: int LED_GetBright( int nLEDID);
        /// 功能: 设置指定显示屏的屏幕亮度
        /// 输入: nLEDID – 设备ID号
        /// lValue – 亮度值
        /// 返回：成功返回0，失败返回-1.
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_GetBright", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_GetBright(int nLEDID)
        {

            Int32 result = 0;
            /*a.	调用InsigmaLEDDriver_Init对动态库进行初始化
             * b.	调用LED_LEDScreenInit，准备对屏幕进行数据组织
             * c.	调用LED_BeginProgram开始编辑新的一个节目，即向屏幕控制器添加一个新的节目，
             * 到LED_EndProgram调用之前的所有操作都针对于当前节目
             * d.	调用一次或多次LED_AddTextBlock或LED_AddBmpBlock或LED_AddClockBlock 向当前节目里添加各种数据区块
             * e.	调用LED_EndProgram 结束对当前节目的编辑操作
f.	如果需要继续添加节目，返回步骤c
g.	将组织好的一屏或多屏的数据调用LED_SendToScreen 发送到目标屏，发送之后目标屏将自动对这些节目开始轮流播放
h.	调用InsigmaLEDDriver_Cleanup 释放动态库
            */
            try
            {
                
               ArrayList led=new ArrayList();
                led.Add(1);
                //led.Add(2); 
                int nScreenType=0;
                string szBackBMP = @"C:\TEMP\QQ3.bmp";
                string szText = "大道本源西方金";
                int nEffectType = 4;
                int nHAlign = 3;
                int nSpeed=1;
                int lTrasnparent = 0;
                int nVAlign = 3;
                LEDBlock rect = new LEDBlock();
                rect.nStartX = 0;
                rect.nStartY = 0;
                rect.nHeight = 32;
                rect.nWidth = 128;
                LEDBlock rect2 = new LEDBlock();
                rect2.nStartX = 43;
                rect2.nStartY = 0;
                rect2.nHeight = 32;
                rect2.nWidth = 42;
                LEDBlock rect3= new LEDBlock();
                rect3.nStartX = 0;
                rect3.nStartY = 0;
                rect3.nHeight = 32;
                rect3.nWidth = 128;
                LEDFontDescriptor lpFont = new LEDFontDescriptor();
                lpFont.lFontColor = 255;
                lpFont.lFontSize = 18;
                lpFont.nBold = 1;
                lpFont.nStrick = 1;
                lpFont.nUnderline = 1;
                lpFont.szFontName = "楷体";
               
                string szBmpFile = @"C:\TEMP\QQ3.bmp";
                LEDClockDescriptor lpClock = new LEDClockDescriptor();
                
                foreach(int ledi in led)
                {
                    //result = LED_LEDScreenInit(ledi, nScreenType, 0, 0);
                   
                    //result = LED_BeginProgram(ledi, 10000, szBackBMP);
                  
                   // result = LED_AddTextBlock(ledi, szText, rect, ref lpFont, nHAlign, nVAlign, nEffectType, nSpeed, lTrasnparent);
               
                    result = LED_AddBmpBlock(nLEDID, szBmpFile, rect, rect3, nEffectType, nSpeed, lTrasnparent);
                    //LED_SendToScreen(ledi);
                    //result = LED_AddClockBlock(nLEDID, rect3, lpClock, ref lpFont, nEffectType, nSpeed, lTrasnparent); 
                    
                    //result=LED_EndProgram(ledi);

                    //result = LED_SendToScreen(dev);
                }
                /**/
            }
            catch (Exception ex)
            {
                
            }
            SXCLEDControl.InsigmaLEDDriver_Cleanup();
            return result;
        } 
        /// <summary>
        /// 3.9	显示屏重启
        /// 定义: int LED_Restart( int nLEDID );
        /// 功能: 对指定的显示屏进行重启操作(重启后如果显示屏内含有固化的帧就显示固化数据，否则不显示)
        /// 输入： nLEDID - 设备ID；
        /// 返回：成功返回0，失败返回-1
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_Restart", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_Restart(int nLEDID)
        {
            Int32 result = 0;
            SXCLEDControl.InsigmaLEDDriver_Cleanup();
            return result;
        }
        /// <summary>
        /// 3.10	校对时钟
        /// 定义: int LED_AdjustCurrentTime( int nLEDID );
        /// 功能: 对指定的显示屏进行当前时间的校对，当显示屏显示的时间值不准确时，通过调用这个函数可以恢复当前精确时间
        /// 输入： nLEDID - 设备ID；
        /// 返回：成功返回0，失败返回-1
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_AdjustCurrentTime", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_AdjustCurrentTime(int nLEDID)
        {

            Int32 result = 0;
            try
            {
                SXCLEDControl.InsigmaLEDDriver_Cleanup();
            }
            catch (Exception ex)
            {
                
            }
            return result;
        }
        /// <summary>
        /// 3.11	预加载位图资源
        /// 定义: int LED_PreUploadBMP( int nLEDID, const char *szBmpFile );
        /// 功能: 预先将指定的位图数据上传到指定的LED显示屏的存储器
        /// 输入: nLEDID - 设备ID号
        /// szBmpFile – 上传图片的完整路径(该完整路径为上传操作的机器上的路径，驱动应主动从给定路径上将该图片上传到控制器上) 
        /// 返回：成功返回0，失败返回-1
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_PreUploadBMP", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_PreUploadBMP( int nLEDID, string szBmpFile )
        {

            Int32 result = 0;
            try
            {
            SXCLEDControl.InsigmaLEDDriver_Cleanup();
            }
            catch (Exception ex)
            {
                
            }
            return result;
        }
        /// <summary>
        /// 3.12	删除预加载的位图
        /// 定义: int LED_RemoveUploadedBmp( int nLEDID, const char *szBmpFile );
        /// 功能: 从控制器上移除指定文件名的图片文件
        /// 输入: nLEDID – 设备ID号
        /// szBmpFile – 要移除的文件名(该文件名是已经上传到控制器里的图片的文件名称，非完整路径,控制器应能识别出该名称，并将它删除)
        /// 返回： 成功返回0，失败返回-1
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_RemoveUploadedBmp", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_RemoveUploadedBmp( int nLEDID, string szBmpFile )
        {

            Int32 result = 0;
            try
            {
                SXCLEDControl.InsigmaLEDDriver_Cleanup(); 
              }
            catch (Exception ex)
            {
                
            }
            return result;
        }
        /// <summary>
        /// 3.13	获取剩余缓存空间
        /// 定义: int LED_GetFreeUploadBmpSpace( int nLEDID );
        /// 功能: 获取指定设备上的剩余的上传图片的缓存空间，以字节为单位
        /// 输入： nLEDID - 设备ID
        /// 返回: 以字节为单位的剩余空间
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_GetFreeUploadBmpSpace", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_GetFreeUploadBmpSpace(int nLEDID)
        {

            Int32 result = 0;
            try
            {
                SXCLEDControl.InsigmaLEDDriver_Cleanup(); 
              }
            catch (Exception ex)
            {
                
            }
            return result;
        }
        /// <summary>
        /// 3.14	屏幕初始化
        /// 定义: int LED_LEDScreenInit( int nLEDID, int nScreenType, int nWidth, int nHeight );
        /// 功能: 在每一次准备向指定屏幕下发数据前，对屏幕进行的初始化操作调用
        /// 输入: nLEDID – 设备ID号
        /// nScreenType – 屏幕类型(目前为异步屏协议，该参数可忽略)
        /// nWidth – 屏幕宽度
        /// nHeight – 屏幕高度
        /// 返回：成功返回0，失败返回-1
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_LEDScreenInit", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_LEDScreenInit(int nLEDID, int nScreenType, int nWidth, int nHeight)
        {
            Int32 result = 0;
            try
            {
                result = SXCLEDControl.LED_LEDScreenInit(nLEDID, nScreenType, nWidth, nHeight);
            }
            catch (Exception ex)
            {
                
            }
            return result;
        }
        /// <summary>
        /// 3.15	  添加一个节目(这里节目的意思是一屏的数据)
        /// 定义: int LED_BeginProgram( int nLEDID,  int lDisplayTime,const char *szBackBMP );
        /// 功能: 向指定的显示屏添加一个节目，如果向显示屏添加了多个节目，那么这些节目将自动轮流切换，切换的时间根据lDisplayTime参数的值，如果szBackBMP为NULL，那么不需要去加载背景图片，如果不为NULL，那么需要根据图片名称去加载一张图片.
        /// 输入: nLEDID – 设备ID号
        /// lDisplayTime – 当前节目的显示时间(以毫秒为单位)
        /// szBackBMP – 背景图片名称
        /// 返回：成功返回0，失败返回-1
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_BeginProgram", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_BeginProgram( int nLEDID,  int lDisplayTime,string szBackBMP )
        {

            Int32 result = 0;
            try
            {
                SXCLEDControl.LED_BeginProgram(nLEDID, lDisplayTime, szBackBMP, 0);
            }
            catch (Exception ex)
            {
                
            }
            return result;
        }
        /// <summary>
        /// 3.16	添加文字区块
        /// 定义: void LED_AddTextBlock( int nLEDID, const char *szText, LEDBlock rect,LPFontDescriptor lpFont, int nHAlign,int nVAlign,int nEffectType, int nSpeed, int lTrasnparent );
        /// 功能: 向当前节目里添加一个文本区块
        /// 输入: nLEDID – 设备ID号
        /// szText – 该区块上显示的文本内容
        /// rect – 区块的区域范围
        /// lpFont – 区块的字体结构
        /// nHAlign – 文字水平对齐方式
        /// nVAlign – 文字垂直对齐方式
        /// nEffectType – 区块的特效方式
        /// nSpeed – 特效的速度(nEffectType>=2 and nEffectType<=5 表示移动的速度，nEffectType=6表示闪烁的频率)
        /// lTrasnparent – 是否透明显示
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_AddTextBlock", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_AddTextBlock(int nLEDID, string szText,LEDBlock rect,ref LEDFontDescriptor lpFont, int nHAlign, int nVAlign, int nEffectType, int nSpeed, int lTrasnparent)
        {

            Int32 result = 0;
            try
            {
                SXCLEDControl.LED_AddTextBlock(nLEDID, szText,rect,lpFont,nHAlign,nVAlign,nEffectType,nSpeed,lTrasnparent);
            }
            catch (Exception ex)
            {
                
            }
            return result;
        }
        /// <summary>
        /// 3.17	添加位图区块
        /// 定义: void LED_AddBmpBlock( int nLEDID,const char *szBmpFile, LEDBlock destRect, LEDBlock sourceRect,int nEffectType,int nSpeed, int  lTrasnparent );
        /// 功能: 在当前节目内添加一个位图区块
        /// 输入: nLEDID – 设备ID号
        /// szBmpFile – 显示的存在于控制器上的位图名称
        /// destRect – 目标区域范围,即把位图显示在那个范围内
        /// sourceRect – 要显示的原图的区域范围
        /// nEffectType – 区块特效方式
        /// nSpeed -特效的速度(nEffectType>=2 and nEffectType<=5 表示移动的速度，nEffectType=6表示闪烁的频率)
        /// lTrasnparent – 背景透明
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_AddBmpBlock", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_AddBmpBlock( int nLEDID,string szBmpFile, LEDBlock destRect, LEDBlock sourceRect,int nEffectType,int nSpeed, int  lTrasnparent )
        {
            //非常要注意双反斜杠c:\\TEMP\\qq.bmp
            Int32 result = 0;
            try
            {
                #region
                /*DataRow dwLeafDetail=SXCLEDControl.LocalData.LEAFDETAIL.NewLEAFDETAILRow();
                string led=nLEDID.ToString(); 
                DataRow dwPicture = SXCLEDControl.LocalData.CPICTURE.NewCPICTURERow();
                string cind = Guid.NewGuid().ToString();
                cind = "4";
                string sys = "000";
                dwLeafDetail["LDSYSTEM"] = sys;
                dwLeafDetail["LDLEDID"] = led; 
                
                dwLeafDetail["LDPROGRAMID"] = "Temp";
                dwLeafDetail["LDLEAFID"] = "Temp";
                dwLeafDetail["LDAREAID"] = "Temp";
                dwLeafDetail["LDCONTENTID"] = cind; 
                dwLeafDetail["LDCONTENTTYPE"] = "CPICTURE";
                dwLeafDetail["LDLTOPX"] = 0;
                dwLeafDetail["LDLTOPY"] = 0;
                dwLeafDetail["LDLBOTTOMX"] = 0;
                dwLeafDetail["LDLBOTTOMY"] =32;
                dwLeafDetail["LDRTOPX"] =128;
                dwLeafDetail["LDRTOPY"] = 0;
                dwLeafDetail["LDRBOTTOMX"] = 128;
                dwLeafDetail["LDRBOTTOMY"] = 32;
                dwLeafDetail["LDNEWDATE"] = DateTime.Now.ToString();
                dwLeafDetail["LDNEWUSER"] = "Temp";

                dwPicture["CPSYSTEM"] = sys;
                dwPicture["CPPICTUREID"] = cind;
                dwPicture["CPPICTUREAME"] = cind;
                dwPicture["CPPICTUREFILE"] = szBmpFile;
                dwPicture["CPWIDTH"] = 57;
                dwPicture["CPHEIGHT"] = 32;
                dwPicture["CPEFFECT"] = nEffectType;
                dwPicture["CPSPEED"] = 1;
                dwPicture["CPTRANSPARENT"] = 0;
               */
                //SXCLEDControl.LocalData.CPICTURE.Rows.Add(dwPicture); 
                //SXCLEDControl.AddLeafDeatail(dwLeafDetail, led, sys);
                #endregion
                IntPtr screenDC = GetDC(IntPtr.Zero);
                IntPtr memDC = CreateCompatibleDC(screenDC);
                Bitmap bmp = new Bitmap(szBmpFile);
                IntPtr hBitmap = bmp.GetHbitmap();
                hBitmap = bmp.GetHbitmap();
                SelectObject(memDC, hBitmap); // Select bitmap from compatible bitmap to memDC        
                DeleteObject(hBitmap);
                ReleaseDC(IntPtr.Zero, screenDC);
                ReleaseDC(IntPtr.Zero, memDC);

                SRECT srect = new SRECT();
                Int32 left = destRect.nStartX;
                Int32 top = destRect.nStartY;
                Int32 right = destRect.nStartX + destRect.nWidth;
                Int32 bottom = destRect.nStartY + destRect.nHeight;
                SetRect(ref srect, left, top, right, bottom);
                short w = 57;
                short h = 32;
                MessageBox.Show("非常要注意双反斜杠以及效果兼容c:\\TEMP\\qq.bmp" );
                AddWindow(memDC, w, h, ref srect, nEffectType, nSpeed, lTrasnparent); 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message+ ex.StackTrace+ex.Source);
                
            }
            return result;
        }
        /// <summary>
        /// 3.18	添加时钟区块
        /// 定义: void LED_AddClockBlock(int nLEDID, LEDBlock rect, LPClockDescriptor lpClock,LPFontDescriptor lpFont, int nEffectType, int nSpeed, int  lTrasnparent );
        /// 功能: 在当前节目内添加一个时钟区块
        /// 输入: nLEDID – 设备ID号
        /// rect – 时钟的区域范围
        /// lpClock – 时钟描述结构
        /// lpFont – 时钟显示的字体
        /// 以下3个参数忽略
        /// nEffectType –  
        /// nSpeed – 
        /// lTrasnparent – 
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_AddClockBlock", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_AddClockBlock(int nLEDID, LEDBlock rect, LEDClockDescriptor lpClock,ref LEDFontDescriptor lpFont, int nEffectType, int nSpeed, int lTrasnparent)
        {

            Int32 result = 0;
            try
            {
                SXCLEDControl.LED_AddClockBlock(nLEDID,rect,lpClock,lpFont,nEffectType,nSpeed,lTrasnparent);
            }
            catch (Exception ex)
            {
                
            }
            return result;
        }
        /// <summary>
        /// 3.19	结束节目编辑
        /// 定义: long LED_EndProgram( int nLEDID );
        /// 功能: 结束对当前(和最近一次LED_BeginProgram调用匹配)节目的编辑，即表示一屏数据组织已经准备完毕.
        /// 输入: nLEDID – 设备ID号
        /// 返回：成功返回0，失败返回-1
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_EndProgram", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_EndProgram( int nLEDID )
        {

            Int32 result = 0;
            try
            {
                SXCLEDControl.LED_EndProgram(nLEDID, 0);
            }
            catch (Exception ex)
            {
                
            }

            return result;
        }
        /// <summary>
        /// 3.20	节目发送
        /// 定义: int LED_SendToScreen ( int nLEDID );
        /// 功能:把对指定屏幕已经组织好的数据一次性的发送到显示屏的控制器上
        /// 注: 在发送节目之前所进行的操作如LED_BeginProgram, LED_ AddTextBlock, LED_AddBmpBlock, LED_ AddClockBlock, LED_ EndProgram操作所组织的数据都保存在动态库中
        /// 输入: nLEDID – 要发送数据的显示屏的ID号
        /// 返回：成功返回0，失败返回-1 
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_SendToScreen", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_SendToScreen ( int nLEDID )
        {

            Int32 result = 0;
            try
            {
                LED_SendToScreen(dev, 1, "192.168.0.101", 6666);
              //result=  SXCLEDControl.LED_SendToScreen(nLEDID, 0);  
            }
            catch (Exception ex)
            {
                
            }
            return result;
        }
        /// <summary>
        /// 3.21	节目固化
        /// 定义: int LED_FastenProgram( int nLEDID );
        /// 功能: 将当前显示屏的数据作为指定显示屏的固化内存，在开机时没有节目的时候播放固化在显示屏内部的节目
        /// 输入: nLEDID – 设备ID号
        /// 返回: 成功返回0，失败返回-1
        /// </summary>
        /// <returns></returns>
        [ExportDllAttribute("LED_FastenProgram", System.Runtime.InteropServices.CallingConvention.Winapi)]
        public static Int32 LED_FastenProgram( int nLEDID )
        {
            Int32 result = 0;
            SXCLEDControl.InsigmaLEDDriver_Cleanup();
            return result;
        }
        #region========LED Sender.dll==============
        [DllImport("LEDSender.dll", EntryPoint = "LED_Open", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 LED_Open(ref PDeviceParam param, Int32 Notify, Int32 Window, Int32 Message);

        [DllImport("LEDSender.dll", EntryPoint = "LED_Query", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_Query(Int32 dev, Byte Address, string Host, UInt16 port);

        [DllImport("LEDSender.dll", EntryPoint = "LED_Close", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_Close(Int32 dev);

        [DllImport("LEDSender.dll", EntryPoint = "LED_AdjustTime", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_AdjustTime(Int32 dev, byte Address, string Host, UInt16 port);

        [DllImport("LEDSender.dll", EntryPoint = "LED_SendToScreen", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_SendToScreen(Int32 dev, byte Address, string Host, UInt16 port);

        [DllImport("LEDSender.dll", EntryPoint = "LED_GetPower", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_GetPower(Int32 dev, byte Address, string Host, UInt16 port);

        [DllImport("LEDSender.dll", EntryPoint = "LED_SetPower", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_SetPower(Int32 dev, byte Address, string Host, UInt16 port, int Power);

        [DllImport("LEDSender.dll", EntryPoint = "LED_GetBrightness", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_GetBrightness(Int32 dev, byte Address, string Host, UInt16 port);

        [DllImport("LEDSender.dll", EntryPoint = "LED_SetBrightness", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_SetBrightness(Int32 dev, byte Address, string Host, UInt16 port, byte Brightness);

        [DllImport("LEDSender.dll", EntryPoint = "LED_GetNotifyMessage", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_GetNotifyMessage(PNotifyMessage Notify);

        [DllImport("LEDSender.dll", EntryPoint = "LED_GetOption", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 LED_GetOption(int Index);

        [DllImport("LEDSender.dll", EntryPoint = "LED_SetOption", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 LED_SetOption(int Index, Int32 Value);
        /// <summary>
        ///   MakeRoot说明
        ///   Function  MakeRoot(RootType: Integer; ScreenType: Integer): Integer; Stdcall; External LEDSender;
        ///   RootType: 可选ROOT_PLAY或ROOT_DOWNLOAD
        ///    ROOT_PLAY: 表示显示内容仅播放，无需保存，控制卡掉电后不再需要显示
        ///    ROOT_DOWNLOAD: 表示显示内容需要保存在主板中，当控制卡上电后自动播放
        ///    (注意：控制卡只能保存1M的数据)
        ///    ScreenType: 必须和控制卡的设置相同，否则将不会显示
        /// </summary>
        /// <param name="RootType"></param>
        /// <param name="ScreenType"></param>
        /// <returns></returns>
        [DllImport("LEDSender.dll", EntryPoint = "MakeRoot", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 MakeRoot(Int32 RootType, Int32 ScreenType);

        [DllImport("LEDSender.dll", EntryPoint = "AddLeaf", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddLeaf(Int32 DisplayTime); //DisplayTime单位为毫秒

        [DllImport("LEDSender.dll", EntryPoint = "AddWindow", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddWindow(IntPtr hdc, Int16 width, Int16 height, ref SRECT rect, Int32 method, Int32 speed, Int32 transparent);

        [DllImport("LEDSender.dll", EntryPoint = "AddDateTime", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddDateTime(ref LPRECT rect, Int32 transparent, string fontname, Int32 fontsize, Int32 fontcolor, Int32 format);

        [DllImport("LEDSender.dll", EntryPoint = "AddString", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddString(string str, ref LPRECT rect, Int32 method, Int32 speed, Int32 transparent, Int32 fontset, Int32 fontcolor);

        [DllImport("LEDSender.dll", EntryPoint = "AddText", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddText(string str, ref LPRECT rect, Int32 method, Int32 speed, Int32 transparent, string fontname, Int32 fontsize, Int32 fontcolor);

        [DllImport("LEDSender.dll", EntryPoint = "AddMovie", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddMovie(string filename, ref SRECT rect, Int32 stretch);

        [DllImport("LEDSender.dll", EntryPoint = "AddCountUp", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddCountUp(ref LPRECT rect, Int32 transparent, string fontname, Int32 fontsize, Int32 fontcolor, Int32 format, LPSYSTEMTIME starttime);

        [DllImport("LEDSender.dll", EntryPoint = "AddCountDown", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddCountDown(ref LPRECT rect, Int32 transparent, string fontname, Int32 fontsize, Int32 fontcolor, Int32 format, LPSYSTEMTIME endtime);

        #endregion
        #region===========user32.dll================
        [DllImport("user32.dll")]
        private static extern IntPtr GetDC(IntPtr hwnd);
        [DllImport("user32.dll")]
        private static extern IntPtr ReleaseDC(IntPtr hc, IntPtr hDest);
        [DllImport("user32.dll")]
        private static extern IntPtr GetWindowDC(IntPtr hwnd);
        [DllImport("user32.dll")]
        private static extern IntPtr GetForegroundWindow();
        [DllImport("user32.dll")]
        private static extern int GetWindowRect(IntPtr hwnd, ref Rect lpRect);
        [DllImport("gdi32.dll")]
        private static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, TernaryRasterOperations dwRop);
        [DllImport("gdi32.dll", ExactSpelling = true, PreserveSig = true, SetLastError = true)]
        static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);

        [DllImport("gdi32.dll")]
        private static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);

        [DllImport("gdi32.dll", SetLastError = true)]
        private static extern IntPtr CreateCompatibleDC(IntPtr hdc);

        [DllImport("gdi32.dll")]
        private static extern bool DeleteObject(IntPtr hObject);
        [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 SetRect(ref SRECT rect, Int32 left, Int32 top, Int32 right, Int32 bottom);

        private enum TernaryRasterOperations : uint
        {
            /// <summary>dest = source</summary> 
            SRCCOPY = 0x00CC0020,
            /// <summary>dest = source OR dest</summary> 
            SRCPAINT = 0x00EE0086,
            /// <summary>dest = source AND dest</summary> 
            SRCAND = 0x008800C6,
            /// <summary>dest = source XOR dest</summary> 
            SRCINVERT = 0x00660046,
            /// <summary>dest = source AND (NOT dest)</summary> 
            SRCERASE = 0x00440328,
            /// <summary>dest = (NOT source)</summary> 
            NOTSRCCOPY = 0x00330008,
            /// <summary>dest = (NOT src) AND (NOT dest)</summary> 
            NOTSRCERASE = 0x001100A6,
            /// <summary>dest = (source AND pattern)</summary> 
            MERGECOPY = 0x00C000CA,
            /// <summary>dest = (NOT source) OR dest</summary> 
            MERGEPAINT = 0x00BB0226,
            /// <summary>dest = pattern</summary> 
            PATCOPY = 0x00F00021,
            /// <summary>dest = DPSnoo</summary> 
            PATPAINT = 0x00FB0A09,
            /// <summary>dest = pattern XOR dest</summary> 
            PATINVERT = 0x005A0049,
            /// <summary>dest = (NOT dest)</summary> 
            DSTINVERT = 0x00550009,
            /// <summary>dest = BLACK</summary> 
            BLACKNESS = 0x00000042,
            /// <summary>dest = WHITE</summary> 
            WHITENESS = 0x00FF0062
        }
        #endregion
    }
}
